import request from '@/utils/request'
const pkg = require('../../../package')
// 常用功能配置  获取一级菜单 根据权限
export function listOnelevelMenu(productId) {
  return request({
    url: `/global/sysmenu/listOnelevelMenu/${productId}`,
    method: 'GET'
  })
}

// 根据产品id  一级菜单id获取树
export function getAllMenuByOne(data) {
  return request({
    url: `/global/sysmenu/getAllMenuListByOne`,
    method: 'POST',
    data
  })
}

// 存常用功能
export function saveCommonMenu(data) {
  return request({
    url: `/global/sysmenuset/315`,
    method: 'POST',
    data
  })
}

// 获取常用功能
export function getCommonMenu() {
  return request({
    url: `/global/sysmenuset/315`,
    method: 'GET'
  })
}

// 获取系统菜单
export function getPermissionProduct() {
  return request({
    url: `/global/common/permissionproduct`,
    method: 'GET'
  })
}

/**
 * 获取行政区域
 * @param {Number} param 获取行政区域列表 1查询省份列表、2查询市列表、3查询区县列表
 * @returns {AxiosPromise}
 */
export function getDistricts(param) {
  return request({
    url: `/global/district/searchDistrictList/${param}`,
    method: 'post',
    data: {}
  })
}

// 获取二级区域
export function getSubDistricts(id) {
  return request({
    url: `/global/district/searchChildList/${id}`,
    method: 'post',
    data: {}
  })
}

/**
 * 数据来源 没有停启用
 * @returns {AxiosPromise}
 */
export function dataSource(data) {
  return request({
    url: '/cecapitalexpend/datasource/search',
    method: 'POST',
    data
  })
}

/**
 * 产品系统
 */
export function getProducts() {
  return request({
    url: '/global/product',
    method: 'GET'
  })
}

/**
 * 科室下拉
 */
export function getDepartment(data) {
  return request({
    url: '/global/department/getStandardDepartmentTree',
    method: 'POST',
    data
  })
}

/**
 * 获取科室职员出差人等
 * @param {Number} proId 产品id
 * @param {Number} state 0启用产品、1全部产品
 * @returns {AxiosPromise}
 */
export function getEmployeeList(proId, state) {
  return request({
    url: `/global/employee/getEmployeeForProduct/${proId}/${state}`,
    method: 'post',
    data: {}
  })
}

/**
 * 获取服务端时间
 */
export function remoteDate() {
  return request({
    url: `/global/common/getServiceDate`,
    method: 'GET'
  })
}

/**
 * 获取单据号
 * @param {Object} data
 * @returns {AxiosPromise}
 */
export function getReceiptNum(data) {
  return request({
    url: '/cecapitalexpend/common/getReceiptNo',
    method: 'post',
    data
  })
}

/**
 * 获取归口科室
 * @param {Object} data
 * @returns {AxiosPromise}
 */
export function getResideDepartments(data) {
  return request({
    url: '/cecapitalexpend/costexecutedetail/getResideDepartment',
    method: 'post',
    data
  })
}

/**
 * 单据模板列表
 * @param {Object} data
 * @returns {AxiosPromise}
 */
export function billTemplates(data) {
  return request({
    url: '/cecapitalexpend/billtemplate/search',
    method: 'post',
    data
  })
}

export function getBillTemplateInfo(id) {
  return request({
    url: `/cecapitalexpend/billtemplate/${id}`,
    method: 'get'
  })
}

// 上传文件
export function uploadFile(data, path) {
  return request({
    url: `/cecapitalexpend/common/uploadfile?filePath=${path}`,
    method: 'post',
    data
  })
}

// 下载文件 需要传参
export function downloadFile(name, path) {
  return request({
    url: `/cecapitalexpend/common/downloadfile?filePath=${path}`,
    method: 'post',
    headers: {
      'Content-Type': 'application/json'
    },
    data: name,
    responseType: 'blob'
  })
}
// 单据动态参数
export function getTemplateData(data) {
  return request({
    url: `/cecapitalexpend/common/getTemplateData`,
    method: 'post',
    data
  })
}
// 获取字典类型
export function dictionType(id) {
  return request({
    url: `/global/datadictionary/searchByType/${id}`,
    method: 'POST'
  })
}

export function getApprovalLogs(data) {
  return request({
    url: `${pkg.baseurl}:30006/leave/workFlowSearchLog?conte`,
    method: 'post',
    data
  })
}

// 公共方法 审批 buttontype按钮类型：1审批、2取消审批、3通过、4驳回、5撤销、6撤回
export function updateApproval(data) {
  return request({
    url: `/global/common/updateApproval`,
    method: 'post',
    data: { lngproductid: 315, ...data }
  })
}

// 往来单位分页
export function getCom(data = {}, page, size) {
  return request({
    url: `/global/customer/search/${page}/${size}`,
    method: 'post',
    data
  })
}

// 表格动态配置 增加 编辑
export function listStyle(data) {
  return request({
    url: `/global/liststyle`,
    method: 'POST',
    data
  })
}

// 表格动态配置 获取
export function findListStyle(data) {
  return request({
    url: `/global/liststyle/findByKey`,
    method: 'POST',
    data
  })
}
